import {createRouter, createWebHistory} from 'vue-router'
import Layout from "../layout/Layout.vue";
import LoginPage from "../pages/LoginPage/LoginPage.vue";


const routes = [
    {
        path: '/login',
        name: 'Login',
        component: LoginPage
    },
    {
        path: '/',
        name: 'Layout',
        component: Layout,
        children: [
            {
                path: '',
                name: 'ShopFront',
                component: () => import('../pages/ShopFront/ShopFront.vue')
            },
            {
                path: 'latestitem',
                name: 'LatestItem',
                component: () => import('../pages/LatestItem/LatestItem.vue')
            },
            {
                path: 'category',
                name: 'Category',
                component: () => import('../pages/CategoryPage/CategoryPage.vue')
            },
            {
                path: 'search',
                name: 'Search',
                component: () => import('../pages/SearchPage/SearchPage.vue')
            },
            {
                path: 'detail',
                name: 'ItemDetail',
                component: () => import('../pages/ItemDetailPage/ItemDetailPage.vue')
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes,
    scrollBehavior(to, from) {
        return {top: 0}
    }
})

// router.beforeEach((to, from, next) => {
//     // if (to.name === 'Login' && localStorage.getItem('token')) {
//     //     next({name: 'Layout'})
//     // } else {
//     //     next()
//     // }
// })


export default router